﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    /// <summary>
    /// 在运行中保存的数据
    /// </summary>
    class RuningData
    {
        //Room的缓存
        public static List<RoomModel> Rooms = new List<RoomModel>();
        #region 操纵Rooms的方法
        public static bool AddRoom(RoomModel room)
        {
            foreach (RoomModel item in Rooms)
            {
                if (item.ID == room.ID)
                {
                    //id相同不插入
                    return false;
                }
            }
            Rooms.Add(room);
            return true;
        }

        public static void UpdateRoom(RoomModel room)
        {
            for(int i = 0; i < Rooms.Count; i++)
            {
                //碰到id相同就跟新
                if(Rooms[i].ID == room.ID)
                {
                    Rooms[i] = room;
                }
            }
            //没有相同的就添加
            Rooms.Add(room);
        }

        public static bool DeleteRoom(RoomModel room)
        {
            foreach(RoomModel item in Rooms)
            {
                if(item.ID == room.ID)
                {
                    Rooms.Remove(room);
                }
            }
            return false;
        }

        public static bool DeleteRoom(int roomId)
        {
            for (int i = 0; i < Rooms.Count; i++)
            {
                if (Rooms[i].ID == roomId)
                {
                    Rooms.RemoveAt(i);
                }
            }
            return false;
        }

        public static RoomModel GetRoom(int roomId)
        {
            foreach(RoomModel item in Rooms)
            {
                if(item.ID == roomId)
                {
                    return item;
                }
            }
            return null;
        }
        #endregion

        //管理加载的页面
        public static Dictionary<String, Form> FormDir = new Dictionary<string, Form>();
    }
}
